/**
 * 课程详情
 */
require("../css/courseDetail.less");
require("../fonts/iconfont.css");
console.log("courseDetail.js");
document.ready(function () {
    const iconback = document.querySelector('.icon-back');
    iconback.addEventListener('click', function () {
        window.history.back()
    })

    /* 获取当前课程的id */
    let courseId = location.search.split('=')[1]

    const courseImg = document.querySelector('#courseImg');
    const newcourseName = document.querySelector('#newcourseName');
    const sumCalorie = document.querySelector('#sumCalorie');
    const sumTime = document.querySelector('#sumTime');
    const peoplenum = document.querySelector('#peoplenum');
    const courseDesc = document.querySelector('#newcourseDesc');
    const instrument = document.querySelector('#instrument');
    const frequency = document.querySelector('#frequency');
    //获取相对应课程的数据
    function getCourseDetail() {
        window.$http.get(`sports/courseDetail?id=${courseId}`, function (res) {
            if (res.status === 0) {
                courseImg.src = 'http://139.9.177.51:8099' + res.data.imgurl;
                newcourseName.textContent = res.data.name;
                sumCalorie.textContent = res.data.calorie;
                sumTime.textContent = res.data.time;
                peoplenum.textContent = res.data.peoplenum;
                courseDesc.textContent = res.data.desc;
                instrument.textContent = res.data.instrument;
                frequency.textContent = res.data.frequency;
                // 把播放器需要的数据存入本地
                window.localStorage.setItem('fragments', JSON.stringify(res.data.fragments))
            }
        })
    }
    getCourseDetail();
    /* 开始训练 */
    const startBtn = document.querySelector('#startBtn')
    startBtn.addEventListener('click', function () {
        window.location.href = `./player.html?id=${courseId}` // 跳转到播放器页面
    })
})